package com.liweitong.minhang.controller;

import com.liweitong.minhang.entity.Admin;
import com.liweitong.minhang.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.*;

/**
 * @Author Weton Li
 * @Date 2021/12/23 18:31
 */
@Controller
public class AdminController {
    @Autowired
    public AdminService adminService;

//    @PostMapping("/login.html")
//    @ResponseBody
    public String faceLogin(Model model) {
//        try {
////            String[] args1=new String[]{"D:\\face_test\\face.vbs"};
//            Process pr = Runtime.getRuntime().exec("wscript D:\\face_test\\face.vbs");
//
////            BufferedReader in = new BufferedReader(new InputStreamReader(
////                    pr.getInputStream()));
////            String line;
////            while ((line = in.readLine()) != null) {
////                System.out.println(line);
////            }
////            in.close();
//            pr.waitFor();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        // no=1
//
//        try {
//            String filePath = "D:\\face_test\\1.txt";
//            FileInputStream fin = new FileInputStream(filePath);
//            InputStreamReader reader = new InputStreamReader(fin);
//            BufferedReader buffReader = new BufferedReader(reader);
//            String strTmp = "";
//            String tmp = "";
//            while ((strTmp = buffReader.readLine()) != null) {
//                tmp = strTmp;
////                System.out.println(tmp);
//            }
//
//            while ("-1".equals(tmp)) {
//                FileInputStream fin1 = new FileInputStream(filePath);
//                InputStreamReader reader1 = new InputStreamReader(fin1);
//                BufferedReader buffReader2 = new BufferedReader(reader1);
//                Thread.sleep(1000);
//                strTmp = buffReader2.readLine();
//                tmp = strTmp;
////                System.out.println(strTmp);
//
//            }
//
//            if ("-2".equals(strTmp)) {
//                Boolean isFail = true;
//                model.addAttribute("isFail",isFail);
//                model.addAttribute("facedFail", "查无此人，登录失败");
//                Writer writer = new FileWriter(filePath);
//                writer.write("-1");
//                writer.close();
//                return "login.html";
//            }
//            buffReader.close();
//
////
//            Writer writer = new FileWriter(filePath);
//            writer.write("-1");
//            writer.close();
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//
//        Admin admin = adminService.getById(1);
//        model.addAttribute("name",admin.getAdminname());
//        if (admin != null) {
            return "list.html";
//        }
//        return "redirect:/login";
////        return "login";
    }

//    @GetMapping("showName")
//    @ResponseBody
//    public void showName(Model model){
//
//        return ;
//    }
}
